/**
 *******************************************************************************
 * @FileName  : hal_flash.c
 * @Author    : GaoQiu
 * @CreateDate: 2023-08-01
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#include "platform/platform.h"

int HalFlashEraseSector(uint32_t addr)
{
	FMC_EraseSector(FLCTL, addr);
	return 0;
}

int HalFlashWrite(uint32_t addr, uint8_t *pdata, uint32_t len)
{
	//FMC_WriteEnable(FLCTL);
	return FMC_WriteStream(FLCTL, addr, pdata, len);
}

int HalFlashRead(uint32_t addr, uint8_t *pRes, uint32_t len)
{
#if 0
	for(int i=0; i<len; i++){
		pRes[i] = FMC_ReadByte(FLCTL, addr+i, CMD_NORM_READ);
	}
#else
	FMC_ReadStream(FLCTL, addr, CMD_NORM_READ, pRes, len);
#endif
	return 0;
}


void HalFlashEraseInfoArea(void)
{
    FMC_EraseInfoArea(FLCTL);
}

void HalFlashWriteInfoArea(uint32_t addr, uint8_t *pdata, uint32_t len)
{
	 FMC_WriteInfoArea(FLCTL, addr, pdata, len);
}

void HalFlashReadInfoArea(uint32_t addr, uint8_t *buf, uint32_t len)
{
	FMC_ReadInfoArea(FLCTL, addr, CMD_FAST_READ, buf, len);
}




